<template>
  <div class="user-event">
    <div style="display: flex">
      <div style="width: 40%">
        <div class="user-title">事件</div>
        <div style="display: flex">
          <div class="user-event-left-item" v-for="item in list">
            <div>{{ item.type }}</div>
            <div :style="{ background: item.background, color: item.color }">
              {{ item.num }}
            </div>
            <div>件</div>
          </div>
        </div>
      </div>
      <div style="width: 55%; margin-left: 5%">
        <el-tabs v-model="activeName">
          <el-tab-pane label="我的待办" name="first">
            <template v-if="todoList.length">
              <div class="user-event-right-item" v-for="item in todoList"   @click="goUrl('/todoItem/todo')">
                <div class="txt-title">
                  {{ item.processDefinitionName || "" }}
                </div>
                <span>{{ item.startTime.replace(/\s.*/, "") || "" }}</span>
              </div>
            </template>
            <span v-else class="txt-span"> 暂无 </span>
          </el-tab-pane>
          <el-tab-pane label="我的已办" name="second">
            <template v-if="doneList.length">
              <div class="user-event-right-item" v-for="item in doneList"  @click="goUrl('/todoItem/done')">
                <div class="txt-title">
                  {{ item.processDefinitionName || "" }}
                </div>
                <span>{{ item.startTime.replace(/\s.*/, "") || "" }}</span>
              </div>
            </template>
            <span v-else class="txt-span"> 暂无 </span>
          </el-tab-pane>
          <el-tab-pane label="公示公告" name="third">
            <template v-if="noticeList.length">
              <div class="user-event-right-item" v-for="item in noticeList" @click="goUrl('/system/noticelist')">
                <div class="txt-title">{{ item.noticeTitle || "" }}</div>
                <span>{{ item.createTime.replace(/\s.*/, "") || "" }}</span>
              </div>
            </template>
            <span v-else class="txt-span"> 暂无 </span>
          </el-tab-pane>
        </el-tabs>
      </div>
    </div>
  </div>
</template>

<script>
import request from "@/utils/request";

export default {
  name: "userIndex",
  components: {},
  data() {
    return {
      activeName: "first",
      list: [
        {
          type: "严重事件",
          en: "Serious",
          num: 0,
          color: "rgb(243,148,51)",
          background: "rgb(255,243,219)",
          enColor: "rgb(255,169,215)",
        },
        {
          type: "重要事件",
          en: "Important",
          num: 0,
          color: "rgb(83,68,190)",
          background: "rgb(216,220,255)",
          enColor: "rgb(144,220,255)",
        },
        {
          type: "一般事件",
          en: "General",
          num: 0,
          color: "rgb(47,138,250)",
          background: "rgb(203,247,231)",
          enColor: "rgb(129,217,227)",
        },
      ],
      todoList: [],
      doneList: [],
      noticeList: [],
    };
  },
  watch: {},
  created() {},
  mounted() {
    this.getData("todoList", "/task/taskTodoList",'post');
    this.getData("doneList", "/task/taskDoneList",'get');
    this.getData("noticeList", "/notice/mylist",'get');
  },
  methods: {
    getData(key, url,method) {
      request({
        url,
        data: {
          pageNum: 1,
          pageSize: 5,
        },
         method,
      }).then((res) => {
        if (res.success) {
          this[key] = (res.rows || []).slice(0, 5);
          // console.log(key, this[key]);
        }
      });
    },
    goUrl(url) {
      this.$router.push({
        path: url,
      });
    },
  },
};
</script>

<style scoped lang="scss">
.user-event {
  margin: 20px 0px 0 0px;
  background: white;
  border-radius: 6px;
  padding: 16px 16px 40px 16px;
  width: 48%;
  width: 700px;
  height: 284px;

  .user-title {
    border-left: 3px solid rgb(138, 205, 255);
    font-weight: bold;
    padding-left: 10px;
    margin-bottom: 10px;
  }
  .user-event-left-item {
    margin-top: 40px;
    width: 33%;
    text-align: center;
    font-weight: bold;
    line-height: 40px;
    div:nth-child(2) {
      font-size: 25px;
      text-align: center;
      width: 80%;
      margin-left: 10%;
      border-radius: 6px;
      line-height: 60px;
    }
  }
  .user-event-right-item {
    // margin-top: 11px;
    // background: rgb(236, 238, 255);
    // border-radius: 4px;
    padding: 0 8px;
    display: flex;
    justify-content: space-between;
    line-height: 36px;
    border-bottom: 0.5px solid #eee;
    cursor: pointer;
    &:nth-child(2n-1) {
      background-color: rgba(0, 0, 0, 0.05);
    }
    div {
      // width: 200px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }

  .txt-title {
    width: 240px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .txt-span {
    display: inline-block;
    width: 100%;
    color: #999;
    border-bottom: 0.5px solid #ddd;
    text-align: center;
    line-height: 180px;
  }
}
</style>
